<template>
  <div class="live">
    <h5>
      <span class="cursor" @click="back()">&lt;返回</span>
      <span v-show="show">{{ title }}</span>
      <span v-show="detailShow">{{ detailTitle }}的直播间</span>
    </h5>
    <router-view></router-view>
    <div class="live-bottom" v-show="show">
      <h2
        v-show="$route.query.title == '京斗云'"
        style="color:red;text-align:center;width:100vw"
      >
        没有直播
      </h2>
      <div class="live-list" v-for="item in liveList" :key="item.room_id">
        <img v-bind:src="item.room_src" v-image-preview alt="" />
        <p @click.stop="showLive(item.nickname)">
          <router-link
            :to="{ name: 'Livedetail', params: { id: item.room_id } }"
            >用户：{{ item.nickname }}</router-link
          >
        </p>
        <p>直播：{{ item.game_name }}</p>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "detail",
  data() {
    return {
      title: "",
      detailTitle: "",
      cate_id: null,
      rome_id: null,
      liveList: [],
      show: true,
      detailShow: false,
    };
  },
  methods: {
    back() {
      this.$router.go(-1);
      if (this.$route.path.includes("/live/livedetail")) {
        this.show = true;
        this.detailShow = false;
        let cate_id = localStorage.getItem("cate_id");
        this.title = localStorage.getItem("title");
        this.axios({
          url: `/api/v1/getColumnRoom/${cate_id}?limit=20&offset=0`,
          method: "GET",
        }).then((res) => {
          this.liveList =
            res.data.data == "栏目ID不能为空" ? [] : res.data.data;
        });
      }
    },
    showLive(value) {
      localStorage.setItem("cate_id", this.cate_id);
      localStorage.setItem("title", this.title);
      this.detailTitle = value;
      this.show = false;
      this.detailShow = true;
    },
  },
  created() {
    let { title, cate_id } = this.$route.query;
    if (this.$route.path.includes("/live/livedetail")) {
      this.detailTitle = localStorage.getItem("detailTitle");
      this.show = false;
      this.detailShow = true;
    }
    this.title = title;
    this.cate_id = cate_id * 1;
    this.axios({
      url: `/api/v1/getColumnRoom/${this.cate_id}?limit=20&offset=0`,
      method: "GET",
    }).then((res) => {
      this.liveList = res.data.data == "栏目ID不能为空" ? [] : res.data.data;
    });
  },
};
</script>

<style lang="less" scoped>
[v-cloak] {
  display: none;
}
.live {
  width: 100vw;
  h5 {
    position: relative;
    padding-left: 5px;
    height: 60px;
    line-height: 60px;
    background-color: yellow;
    span:nth-child(1) {
      position: absolute;
      left: 10px;
    }
    span:nth-child(2) {
      color: red;
    }
    span:nth-child(3) {
      color: red;
    }
  }
  .live-bottom {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    background-color: rgb(233, 230, 230);
    padding: 8px;
    .live-list {
      background-color: #fff;
      border-radius: 10px;
      padding: 20px 0px;
      margin-bottom: 10px;
      width: calc((100vw - 30px) / 2);
      img {
        width: 90%;
        margin-bottom: 10px;
      }
      p {
        font-size: 14px;
        zoom: 0.9;
        text-align: left;
        margin-left: 15px;
        line-height: 24px;
        a {
          display: block;
        }
      }
    }
  }
}
</style>
